import { InfoCrudMixin } from 'lin-mizar';
import { merge } from 'lodash';
import { Sequelize, Model, DataTypes } from 'sequelize';
import sequelize from '../lib/db';

class Malfunction extends Model {

}

Malfunction.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    elevatorId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '电梯的ID'
    },
    type: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '故障类型，1：xxx损坏'
    },
    department: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '申报人部门'
    },
    userId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '申报人ID'
    },
    date: {
      type: DataTypes.DATE,
      allowNull: false,
      comment: '故障时间'
    },
    describe: {
      type: Sequelize.STRING,
      allowNull: true,
      comment: '描述详情'
    }
  },
  merge(
    {
      sequelize,
      tableName: 'malfunction',
      modelName: 'malfunction'
    },
    InfoCrudMixin.options
  )
);

class MalfunctionType extends Model {

}

MalfunctionType.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    name: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '故障名称'
    },
    type: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '故障对应电梯类型 1：手扶梯 2：步梯 3：直梯'
    }
  },
  merge(
    {
      sequelize,
      tableName: 'malfunctionType',
      modelName: 'malfunctionType'
    },
    InfoCrudMixin.options
  )
);

export { Malfunction as MalfunctionModel, MalfunctionType as MalfunctionTypeModel };
